#ifndef SPI_FLASH_H
#define SPI_FLASH_H

#define BLOCK_SIZE 32

void flash_init(void);
// 计算74091948字节的校验和
uint32_t flash_crc_all_table(void);
int flash_crc_block(int block_id);
// 读取2KB
void flash_page_read(uint16_t page_addr, uint8_t *buf);
// 写入2KB,成功返回0,失败返回非零
// in_buf长度至少有2112
int flash_write_page(uint16_t page_addr, const uint8_t *in_buf);
// 擦除128KB,成功返回0,失败返回非零
int flash_erase_block(uint16_t page_addr);

// test code
/*
  int succ = flash_erase_block(0);
  printf("test flash_erase_block %d\n", succ);
  const uint8_t in_buf[2112] = {0,1,2,3};
  succ = flash_write_page(0, in_buf);
  printf("test flash_write_page %d\n", succ);
  uint8_t buf[2048] = {0};
  flash_page_read(0, buf);
  printf("%d %d %d %d\n", buf[0], buf[1], buf[2], buf[3]);
*/

#endif

